home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / editor / auror300.zip / PROJSAVE.AML < prev    next >
Text File  |  1996-07-17  |  3KB  |  114 lines

  1. //--------------------------------------------------------------------
  2. // PROJSAVE.AML
  3. // Save Project, (C) 1993-1996 by nuText Systems
  4. //
  5. // (see Projsave.dox for user help)
  6. //
  7. // This macro saves the current state of the editor as a 'project'. If
  8. // the filename is not passed as arg 3, then the user is prompted to
  9. // enter the project filename.
  10. //
  11. // Usage:
  12. //
  13. // Select this macro from the Macro List (on the Macro menu), or run it
  14. // from the macro picklist <shift f12>.
  15. //--------------------------------------------------------------------
  16.  
  17. // compile time macros and function definitions
  18. include bootpath "define.aml"
  19.  
  20. // bookmark history buffer
  21. constant HISTORY = '_book'
  22.  
  23. // book field delimiters and regexp patterns
  24. constant DELIM = '\x00'
  25. constant FIELD = '{[~' + DELIM + ']+}' + DELIM + '#'
  26. constant BOOKFIELDS = FIELD + FIELD + FIELD + FIELD + FIELD + FIELD
  27.  
  28. // mark history buffer
  29. constant MARK = '_mark'
  30.  
  31. // temporary bookmark name
  32. constant tempbook = '@T'
  33.  
  34. // save bookmarks in all buffers
  35. buffer = getcurrbuf
  36. oldbuf = buffer
  37. while buffer do
  38.  
  39.   gotobuf buffer
  40.   name = getbufname
  41.  
  42.   // delete old bookmarks from the history buffer for this file
  43.   oldbuf = gotobuf HISTORY
  44.   if oldbuf then
  45.     while find DELIM + name + DELIM do
  46.       delline
  47.       col 1
  48.     end
  49.     gotobuf oldbuf
  50.   end
  51.  
  52.   // check for bookmarks in the current buffer
  53.   bookmark = getcurrbook
  54.   if bookmark then
  55.  
  56.     // save the current cursor position and window view in
  57.     // a temporary bookmark
  58.     setbook tempbook
  59.  
  60.     // cycle through the bookmarks for this buffer
  61.     while bookmark do
  62.       if bookmark <> tempbook then
  63.         // move cursor to the bookmark --and change the window view
  64.         gotobook bookmark
  65.         addhistory HISTORY bookmark + DELIM + name + DELIM +
  66.                    getviewleft + DELIM + getviewtop + DELIM +
  67.                    getcol + DELIM + getrow + DELIM
  68.       end
  69.       bookmark = getprevbook bookmark
  70.     end
  71.  
  72.     // restore the cursor position and window view
  73.     // and destroy the temp bookmark
  74.     gotobook tempbook
  75.     destroybook tempbook
  76.   end
  77.  
  78.   buffer = getprevbuf buffer
  79. end
  80.  
  81. // save marked block if present
  82. if mark? then
  83.   marktype = getmarktype
  84.   destroybuf MARK
  85.   addhistory MARK (concat
  86.     (case marktype
  87.        when 'l' 'markline'
  88.        when 'k' 'markcolumn'
  89.        when 'c' 'markchar'
  90.        when 's' 'markstream'
  91.      end) ' '
  92.  
  93.     (if marktype <> 'l' then
  94.        getmarkleft + ' ' + (getmarkright + (if? marktype == 's' 1)) + ' '
  95.      end)
  96.     (getmarktop) ' ' (getmarkbot) " '' (findbuf '"
  97.       (sub '\\' '\\\\' (getbufname (getmarkbuf))) "')"
  98.   )
  99. end
  100.  
  101. file = arg 3
  102. if not file then
  103.   file = ask "Save current state to project file" "_load"
  104. end
  105.  
  106. if file then
  107.   currdesk
  108.   if savehistory (qualify (defext file "prj") (getbufname)) then
  109.     display
  110.   else
  111.     msgbox "Can't save " + file
  112.   end
  113. end
  114.